//
//  DVUserModel.m
//  DVActivity
//
//  Created by pan Shiyu on 13-5-6.
//  Copyright (c) 2013年 pan Shiyu. All rights reserved.
//

#import "DVUserModel.h"
#import "DVAPISetting.h"
#import "DVAppSession.h"
#import "CMNetwork.h"

@implementation DVUserModel

+ (void)createUserIDByName:(NSString*)name
                     uerID:(NSString*)userID
                  password:(NSString*)password
                     phone:(NSString*)phone
                   success:(void (^)(NSString *newUid))success
                   failure:(void (^)(NSError *error))failure {
    NSString *path = [NSString stringWithFormat:@"%@/user/getNewId",URL_BASE];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:name forKey:@"name"];
    [params setValue:userID forKey:@"uid"];
    [params setValue:phone forKey:@"phone_no"];
    [params setValue:password forKey:@"password"];
    [params setValue:[DVAppSession sharedAppSession].deviceId forKey:@"device_no"];
    
    [CMNetwork getPath:path
            parameters:params
               success:^(NSDictionary *result, NSData *responseObject) {
                   if (result && [result isKindOfClass:[NSDictionary class]]) {
                       int statusNum = [[result valueForKey:@"status"] intValue];
                       NSString *newUid = [result valueForKey:@"uid"];
                       
#warning TODO psy:这里的判断还需要更细，然后，需要整理出一个相对通用的数据正确性判断逻辑
                       //1-创建新用户成功,2-用户已存在，-1-创建新用户失败
                       if (statusNum == 1 && newUid) {
                           success(newUid);
                           return ;
                       }
                   }
                   
                   failure(nil);
               } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                   failure(error);
               }];
}

+ (void)requestUserInfoByUID:(NSString*)userID
                     success:(void (^)(DVUserInfo *userInfo))success
                     failure:(void (^)(NSError *error))failure {
    
}

@end
